package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import form.ConnectionDB;

import model.Nghenghiep;

public class NghenghiepDAO {

	public static ArrayList<Nghenghiep> select() throws ClassNotFoundException,
			SQLException {
		Connection connection = ConnectionDB.getConnection();
		ArrayList<Nghenghiep> arrNghenghiep = new ArrayList<>();
		String sql = "Select * from Nghenghiep";
		PreparedStatement ps = connection.prepareStatement(sql);
		ResultSet resultSet = ps.executeQuery();
		while (resultSet.next()) {
			String nghenghiep_id = resultSet.getString(1);
			String tennghenghiep = resultSet.getString(2);
			arrNghenghiep.add(new Nghenghiep(nghenghiep_id, tennghenghiep));

		}
		connection.close();
		return arrNghenghiep;

	}

	public static void main(String[] args) throws ClassNotFoundException,
			SQLException {
		// ArrayList<Nghenghiep> arrNghenghiep = NghenghiepDAO.select();
		// for (Nghenghiep nghenghiep : arrNghenghiep) {
		// System.out.println(nghenghiep.toString());
		// }
	}

}
